<?php
	class GoodStudentModel extends Model {
		function GoodStudentModel()
		{
			parent::Model();			
		}
		
		function addGoodStudent($user)
		{
			$data = array(
               'student_name' => $user['student_name'] ,
               'detail' => $user['detail'] ,
			   'show_main_page' => $user['show_main_page'],
			   'seq' => $user['seq'],
			   'create_by' => $user['create_by'],
			   'is_active' => 1
            );
            $this->db->set('create_date', 'NOW()', FALSE); 
			$this->db->insert('good_student', $data);
			return $this->db->insert_id();
		}
		
		function updateGoodStudentImagePath($user)
		{			
			$data = array(
               'student_path' => $user['student_path']			   
            );
            $this->db->where('good_student_id', $user['good_student_id']);
			$this->db->update('good_student', $data); 
		}
		
		function updateGoodStudent($user)
		{			
			$data = array(
               'student_name' => $user['student_name'] ,
               'detail' => $user['detail'] ,
			   'show_main_page' => $user['show_main_page'],
			   'update_by' => $user['update_by']
            );
            $this->db->set('update_date', 'NOW()', FALSE); 
            $this->db->where('good_student_id', $user['good_student_id']);
			$this->db->update('good_student', $data); 
		}
		
		function updateSeq($studentID, $seq, $user)
		{			
			$data = array(
               'seq' => $seq,
			   'update_by' => $user
            );
            $this->db->set('update_date', 'NOW()', FALSE); 
            $this->db->where('good_student_id', $studentID);
			$this->db->update('good_student', $data); 
		}
		
		function getGoodStudent()
		{
			$this->db->order_by("seq", "asc"); 
			$query = $this->db->get_where('good_student', array('is_active' => 1));
			
			return $query->result();
		}
		
		function getFeedBack()
		{
			$this->db->order_by("seq", "asc"); 
			$query = $this->db->get_where('good_student', array('show_main_page' => 'Y', 'is_active' => 1));
			
			return $query->result();
		}
		
		function getGoodStudentByStudentID($user)
		{
			$query = $this->db->get_where('good_student', array('good_student_id' => $user, 'is_active' => 1));
			return $query->row_array();
		}
		
		function getMaxSeq()
		{
			$this->db->select_max('seq');
			$query = $this->db->get('good_student');
			$data = $query->row_array();
			if($data['seq'] == null)
				return 1;
				
			return $data['seq']+1;
		}
		
		function delete($id)
		{
			$data = array(
               'is_active' => 0,
			   'update_by' => $this->session->userdata('username')   
            );
            $this->db->set('update_date', 'NOW()', FALSE); 
            $this->db->where('good_student_id', $id);
			$this->db->update('good_student', $data); 
		}
	}
?>